package com.example.demosecurityjwtlogin.repository;
import com.example.demosecurityjwtlogin.models.Bean;
import org.apache.ibatis.annotations.*;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;


import java.util.List;

@Mapper
public interface BeanMapper extends JpaRepository<Bean,Long> {
    List<Bean> getBooksByuserStartingWith(String user);
    List<Bean> getBooksBybalanceGreaterThan(Integer balance);

    @Query(value = "select * from bean where id=(select max(id) from bean )",
            nativeQuery = true)
    Bean getMaxIdBook () ;

    @Query ("select b from bean b where b.id>:id and b.user=:user")
    List<Bean> getBooksByIdAndAuthor (@Param("user") String user ,
                                      @Param("id") Long id);
    @Query("SELECT b from bean b where b.id<?2 and b.user like %?1%")
    List<Bean> getBooksByIdAndName(String user, Long id);
}
